package com.blb.day20231107login.controller;


import com.blb.day20231107login.entity.ResponseResult;
import com.blb.day20231107login.util.OssUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * OSS文件上传
 */
@CrossOrigin
@RestController
public class UploadController {

    @RequestMapping("/upload")
    public ResponseResult<String> upload(MultipartFile file) throws IOException {
        String filename = file.getOriginalFilename();
        OssUtil.upload(file.getInputStream(), filename);
        String url = OssUtil.getURL(filename);
        return ResponseResult.ok(url);
    }
}
